class MorseCharacter {
  final String character;
  final String morseCode;
  final List<MorseElement> elements;

  const MorseCharacter({
    required this.character,
    required this.morseCode,
    required this.elements,
  });
}

enum MorseElement { dot, dash }

class MorseData {
  static const List<MorseCharacter> characters = [
    // Letters A-Z
    MorseCharacter(character: 'A', morseCode: '·−', elements: [MorseElement.dot, MorseElement.dash]),
    MorseCharacter(character: 'B', morseCode: '−···', elements: [MorseElement.dash, MorseElement.dot, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: 'C', morseCode: '−·−·', elements: [MorseElement.dash, MorseElement.dot, MorseElement.dash, MorseElement.dot]),
    MorseCharacter(character: 'D', morseCode: '−··', elements: [MorseElement.dash, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: 'E', morseCode: '·', elements: [MorseElement.dot]),
    MorseCharacter(character: 'F', morseCode: '··−·', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dash, MorseElement.dot]),
    MorseCharacter(character: 'G', morseCode: '−−·', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dot]),
    MorseCharacter(character: 'H', morseCode: '····', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: 'I', morseCode: '··', elements: [MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: 'J', morseCode: '·−−−', elements: [MorseElement.dot, MorseElement.dash, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: 'K', morseCode: '−·−', elements: [MorseElement.dash, MorseElement.dot, MorseElement.dash]),
    MorseCharacter(character: 'L', morseCode: '·−··', elements: [MorseElement.dot, MorseElement.dash, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: 'M', morseCode: '−−', elements: [MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: 'N', morseCode: '−·', elements: [MorseElement.dash, MorseElement.dot]),
    MorseCharacter(character: 'O', morseCode: '−−−', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: 'P', morseCode: '·−−·', elements: [MorseElement.dot, MorseElement.dash, MorseElement.dash, MorseElement.dot]),
    MorseCharacter(character: 'Q', morseCode: '−−·−', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dot, MorseElement.dash]),
    MorseCharacter(character: 'R', morseCode: '·−·', elements: [MorseElement.dot, MorseElement.dash, MorseElement.dot]),
    MorseCharacter(character: 'S', morseCode: '···', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: 'T', morseCode: '−', elements: [MorseElement.dash]),
    MorseCharacter(character: 'U', morseCode: '··−', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dash]),
    MorseCharacter(character: 'V', morseCode: '···−', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dash]),
    MorseCharacter(character: 'W', morseCode: '·−−', elements: [MorseElement.dot, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: 'X', morseCode: '−··−', elements: [MorseElement.dash, MorseElement.dot, MorseElement.dot, MorseElement.dash]),
    MorseCharacter(character: 'Y', morseCode: '−·−−', elements: [MorseElement.dash, MorseElement.dot, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: 'Z', morseCode: '−−··', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dot, MorseElement.dot]),
    
    // Numbers 0-9
    MorseCharacter(character: '0', morseCode: '−−−−−', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dash, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: '1', morseCode: '·−−−−', elements: [MorseElement.dot, MorseElement.dash, MorseElement.dash, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: '2', morseCode: '··−−−', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dash, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: '3', morseCode: '···−−', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dash, MorseElement.dash]),
    MorseCharacter(character: '4', morseCode: '····−', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dash]),
    MorseCharacter(character: '5', morseCode: '·····', elements: [MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: '6', morseCode: '−····', elements: [MorseElement.dash, MorseElement.dot, MorseElement.dot, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: '7', morseCode: '−−···', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dot, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: '8', morseCode: '−−−··', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dash, MorseElement.dot, MorseElement.dot]),
    MorseCharacter(character: '9', morseCode: '−−−−·', elements: [MorseElement.dash, MorseElement.dash, MorseElement.dash, MorseElement.dash, MorseElement.dot]),
  ];

  static MorseCharacter? getCharacter(String char) {
    try {
      return characters.firstWhere(
        (element) => element.character.toUpperCase() == char.toUpperCase(),
      );
    } catch (e) {
      return null;
    }
  }

  static List<MorseCharacter> get letters => characters.where((c) => RegExp(r'[A-Z]').hasMatch(c.character)).toList();
  static List<MorseCharacter> get numbers => characters.where((c) => RegExp(r'[0-9]').hasMatch(c.character)).toList();
}
